home *** CD-ROM | disk | FTP | other *** search
/ Electronic Clipper 1995 April / Electronic Clipper 1995-04.iso / pc / pc_users / ideasrc / setup / samples / common.cpp < prev    next >
C/C++ Source or Header  |  1993-03-24  |  6KB  |  188 lines

  1.  
  2. // ---------------------------------------------------------------------
  3. //
  4. // COMMON.CPP   - QuickTime for Windows Sample Decompressor
  5. //
  6. //                Version 1.1
  7. //
  8. //                (c) 1988-1993 Apple Computer, Inc. All Rights Reserved.
  9. //
  10. // ---------------------------------------------------------------------
  11.  
  12.  
  13. // Windows header files
  14. #include <windows.h>
  15. #include <windowsx.h>
  16.  
  17. // Compiler header files
  18. #include <ver.h>
  19.  
  20. // Application header files
  21. #include "prototyp.hp"
  22.  
  23. // Local functions
  24. static VOID FAR PASCAL FixupCM( ENTRYFUNC lpfnCM) ;
  25. static VOID FAR PASCAL FixupTB( ENTRYFUNC lpfnTB) ;
  26.  
  27. // Global data
  28. ENTRYFUNC lpfnQTComponentManager ;
  29. ENTRYFUNC lpfnQTToolbox ;
  30. extern ComponentDescription cdTable[] ;     // components in this DLL
  31.  
  32. /* function cfCanDoSelect:
  33.    Report if a function is implemented
  34. */
  35. ComponentResult QTAPI cfCanDoSelect( STKOFF_CMP so, LONG lFunctionSelector)
  36. {
  37.   switch ( lFunctionSelector)  {            // switch on function selector
  38.     case kComponentOpenSelect :
  39.     case kComponentCloseSelect :
  40.     case kComponentCanDoSelect :
  41.     case kComponentVersionSelect :
  42.     case kComponentRegisterSelect :
  43.     case kComponentTargetSelect :
  44.     case codecPreDecompress :
  45.     case codecBandDecompress :
  46.     case codecCDSequenceBusy :
  47.     case codecGetCodecInfo :
  48.       return TRUE ;
  49.     default :
  50.       return FALSE ;
  51.   }  // switch on function selector
  52. }  // cfCanDoSelect
  53.  
  54. /* function RegisterSelect:
  55.    Return 0 as there is nothing to check before registering
  56. */
  57. ComponentResult QTAPI cfRegisterSelect( STKOFF_CMP so, ComponentInstance ci)
  58. {
  59.    return 0;
  60. }  // cfRegisterSelect
  61.  
  62. /* function TargetSelect:
  63.    Not implemented
  64. */
  65. ComponentResult QTAPI cfTargetSelect( STKOFF_CMP so, ComponentInstance ci)
  66. {
  67.   // successful return
  68.   return noErr ;
  69. }  // cfTargetSelect
  70.  
  71. /* function cfVersionSelect:
  72.    Return the version of this component.  We take the information directly
  73.    the Windows version information.
  74. */
  75. ComponentResult QTAPI cfVersionSelect( STKOFF_CMP so, ComponentInstance ci)
  76. {
  77.   // load VER.DLL
  78.   UINT uOldErrorMode = SetErrorMode( SEM_NOOPENFILEERRORBOX) ;// no message box
  79.   HINSTANCE hLibrary = LoadLibrary( "ver.dll") ;
  80.   SetErrorMode( uOldErrorMode) ;            // restore application's settings
  81.   if ( hLibrary < HINSTANCE_ERROR)          // if load error
  82.     return -1 ;                             // take error return
  83.  
  84.   // locate the exported functions of interest
  85.   typedef DWORD (WINAPI *PGETFILEVERSIONINFOSIZE) (LPCSTR, DWORD FAR *) ;
  86.   typedef BOOL (WINAPI *PGETFILEVERSIONINFO) (LPCSTR, DWORD, DWORD, LPVOID) ;
  87.   typedef BOOL ( WINAPI *PVERQUERYVALUE) ( const VOID FAR *
  88.                                          , LPCSTR
  89.                                          , VOID FAR * FAR *
  90.                                          , UINT FAR *
  91.                                          ) ;
  92.   PGETFILEVERSIONINFOSIZE pGetFileVersionInfoSize
  93.     = ( PGETFILEVERSIONINFOSIZE) GetProcAddress( hLibrary, "#6") ;
  94.   PGETFILEVERSIONINFO pGetFileVersionInfo
  95.     = ( PGETFILEVERSIONINFO) GetProcAddress( hLibrary, "#7") ;
  96.   PVERQUERYVALUE pVerQueryValue
  97.     = ( PVERQUERYVALUE) GetProcAddress( hLibrary, "#11") ;
  98.   if ( pGetFileVersionInfoSize == 0
  99.        ||  pGetFileVersionInfo == 0
  100.        ||  pVerQueryValue == 0)  {
  101.     FreeLibrary( hLibrary) ;                // clean up
  102.     return -1 ;                             // take error return
  103.   }  // if any GetProcAddress call failed
  104.  
  105.   // get this module's file name
  106.   char szFilename[ _MAX_PATH] ;
  107.   if ( GetModuleFileName( GetInstOfThisMod()
  108.                         , szFilename
  109.                         , sizeof szFilename
  110.                         ) == 0)  {
  111.     FreeLibrary( hLibrary) ;                // clean up
  112.     return -1 ;                             // take error return
  113.   }  // if GetModuleFileName failed
  114.  
  115.   // get version data
  116.   DWORD hVer
  117.       , dwSize = ( *pGetFileVersionInfoSize)( szFilename, &hVer)
  118.       ;
  119.   if ( dwSize == 0)  {                      // if error
  120.     FreeLibrary( hLibrary) ;                // clean up
  121.     return -1 ;                             // take error return
  122.   }  // if error from GetFileVersionInfoSize
  123.   BYTE abData[ 512] ;
  124.   if ( ( *pGetFileVersionInfo)( szFilename, hVer, dwSize, abData) == FALSE)  {
  125.     FreeLibrary( hLibrary) ;                // clean up
  126.     return -1 ;                             // take error return
  127.   }  // if error from GetFileVersionInfo
  128.   UINT uiSize ;
  129.   VS_FIXEDFILEINFO FAR *lpvsffi ;
  130.   if ( ( *pVerQueryValue) ( abData
  131.                           , "\\"
  132.                           , ( VOID FAR * FAR *) &lpvsffi
  133.                           , &uiSize
  134.                           ) == FALSE)  {    // if error
  135.     FreeLibrary( hLibrary) ;                // clean up
  136.     return -1 ;                             // take error return
  137.   }  // if error from VerQueryValue
  138.   LONG lVersion = ( HIWORD( lpvsffi->dwProductVersionMS) << 4)
  139.                   +  ( LOWORD( lpvsffi->dwProductVersionMS) << 8)
  140.                   +  HIWORD( lpvsffi->dwProductVersionLS)
  141.                   ;
  142.  
  143.   // clean up and return version number to caller
  144.   FreeLibrary( hLibrary) ;
  145.   return lVersion ;
  146. }  // cfVersionSelect
  147.  
  148. /* function FixupCM:
  149.    Establish direct linkage to Component Manager
  150. */
  151. static VOID FAR PASCAL FixupCM( ENTRYFUNC lpfnCM)
  152. {
  153.   lpfnQTComponentManager = lpfnCM;
  154. }  // FixupCM
  155.  
  156. /* function FixupTB:
  157.    Establish direct linkage to Movie Toolbox
  158. */
  159. static VOID FAR PASCAL FixupTB( ENTRYFUNC lpfnTB)
  160. {
  161.   lpfnQTToolbox = lpfnTB;
  162. }  // FixupTB
  163.  
  164. /* function THNGIDENTIFY:
  165.    Entry point called by Component Manager
  166.  
  167.    The function fills the Component ID structure.
  168. */
  169. OSType FAR PASCAL THNGIDENTIFY( LPCID FAR *lplpcid)
  170. {
  171.   // allocate memory for CID information
  172.   // The memory will be freed by the Component Manager.
  173.   LPCID lpcid = ( LPCID) GetMemory( sizeof CID) ;
  174.   if ( lpcid == 0)                          // if allocation failed
  175.     return 0 ;                              // take error return
  176.  
  177.   // fill the structure
  178.   lpcid->lVersion = CID_VERSION ;
  179.   lpcid->sComponentCount = 1 ;
  180.   lpcid->lpcdTable = ( LPCD) &cdTable ;
  181.   lpcid->lpfnTBFixup = FixupTB ;
  182.   lpcid->lpfnCMFixup = FixupCM ;
  183.   *lplpcid = lpcid ;
  184.  
  185.   // return to caller
  186.   return THING ;
  187. }  // THNGIDENTIFY
  188.